package org.example.controller;

import lombok.extern.slf4j.Slf4j;
import org.example.json.PostRequest;
import org.example.json.Responsez;
import org.example.mapper.ConcernMapper;
import org.example.mapper.PostMapper;
import org.example.pojo.Category;
import org.example.pojo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/post")
@Slf4j
public class PostAddController  {

    @Autowired
    private PostMapper postMapper;

    @PostMapping("/create")
    public ResponseEntity<?> createPost(@RequestBody PostRequest postRequest) {
        // 这里可以添加业务逻辑来处理帖子创建

        // 假设帖子创建成功
        boolean isCreated = true; // 这里应该是实际的业务逻辑结果

        if (isCreated) {
            postMapper.addPost(postRequest.getUserId(),postRequest.getContent(),postRequest.getImagePath());
            return ResponseEntity.ok(new Responsez(1, "发布成功", null));
        } else {
            return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(new Responsez(0, "发布失败", null));
        }
    }





}